//数组模拟单链表
#include<iostream>

using namespace std;

const int N = 100010;

int nx, head = -1;
int e[N], ne[N];

void h_insert(int x){
	e[nx] = x, ne[nx] = head, head = nx ++;
} 

void del(int k){
	ne[k] = ne[ne[k]];
}

void insert(int k, int x){
	e[nx] = x, ne[nx] = ne[k], ne[k] = nx ++;
}

int main(){
	int m;
	cin >> m;
	
	while(m -- ){
		int k, x;
		char op;
		
		cin >> op;
		if(op == 'H'){
			cin >> x;
			h_insert(x);
		}
		else if(op == 'D'){
			cin >> k;
			if(k == 0) head = ne[head];
			else del(k - 1 );
		}
		else {
			cin >> k >> x;
			insert(k - 1, x);
		}
	}
	for(int i = head; i != -1; i = ne[i]) cout << e[i] << ' ';
	cout << endl;
	return 0;
}